package cn.tedu.blog.server.controller.api;

import cn.tedu.blog.server.pojo.dto.UserUserAddNewDTO;
import cn.tedu.blog.server.service.IUserUserService;
import cn.tedu.blog.server.utils.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@Api(tags = "3.关注博主模块")
@RequestMapping("/follows")
public class ApiUserUserController {

    @Autowired
    private IUserUserService userUserService;

    @ApiOperation("关注博主个数")
    @ApiOperationSupport(order = 100)
    @GetMapping("/counts")
    public JsonResult followCount(){
        log.info("查询用户关注博主个数");
        int favoriteSize = userUserService.followCountByUserId();
        return JsonResult.ok(favoriteSize);
    }

    @ApiOperation("粉丝个数")
    @ApiOperationSupport(order = 200)
    @GetMapping("/countFans")
    public JsonResult fansCount(){
        log.info("查询用户关注博主个数");
        int fansSize = userUserService.followUserCountByUserId();
        return JsonResult.ok(fansSize);
    }
    @ApiOperation("取消关注")
    @ApiOperationSupport(order = 300)
    @PostMapping("/deleteUserUserById")
    public JsonResult deleteUserUserById(@RequestBody UserUserAddNewDTO userUserAddNewDTO){
        log.info("接收到参数:{}", userUserAddNewDTO);
        userUserService.deleteUserUserById(userUserAddNewDTO);
        return JsonResult.ok("取消关注成功!");
    }

    @ApiOperation("关注")
    @ApiOperationSupport(order = 400)
    @PostMapping("/insertUserUser")
    public JsonResult insertUserUser(@RequestBody UserUserAddNewDTO userUserAddNewDTO){
        log.info("接收到参数:{}", userUserAddNewDTO);
        userUserService.UserUserAddNew(userUserAddNewDTO);
        return JsonResult.ok("关注成功");
    }

    @ApiOperation("判断是否关注此博主")
    @ApiOperationSupport(order = 400)
    @PostMapping("/concerned")
    public JsonResult concerned(@RequestBody UserUserAddNewDTO userUserAddNewDTO){
        log.info("接收到参数:{}", userUserAddNewDTO);
        Boolean concerned = userUserService.concerned(userUserAddNewDTO);
        return JsonResult.ok(concerned.toString());
    }
}
